package com.woniu.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EndTestMqConfig {
    private static final String END_TEST_QUEUE_NAME = "endTestQueue";
    private static final String END_TEST_EXCHANGE_NAME = "endTestExchange";
    private static final String END_TEST_ROUTING_KEY = "endTest";

    private static final String START_TEST_QUEUE_NAME = "startTestQueue";
    private static final String START_TEST_EXCHANGE_NAME = "startTestExchange";
    private static final String START_TEST_ROUTING_KEY = "startTest";
    @Bean
    public Queue startTestQueue(){
        return QueueBuilder.durable(START_TEST_QUEUE_NAME)
                .ttl(1000*60*60)
                .deadLetterExchange(END_TEST_EXCHANGE_NAME)
                .deadLetterRoutingKey(END_TEST_ROUTING_KEY)
                .build();
    }
    @Bean
    public DirectExchange startTestExchange(){
        return new DirectExchange(START_TEST_EXCHANGE_NAME);
    }


    @Bean
    public Binding startTestBinding(){
        return BindingBuilder.bind(startTestQueue())
                .to(startTestExchange())
                .with(START_TEST_ROUTING_KEY);
    }
    @Bean
    public Queue endTestQueue(){
        return QueueBuilder.durable(END_TEST_QUEUE_NAME)
                .build();
    }

    @Bean
    public DirectExchange endTestExchange(){
        return new DirectExchange(END_TEST_EXCHANGE_NAME);
    }


    @Bean
    public Binding endTestBinding(){
        return BindingBuilder.bind(endTestQueue())
                .to(endTestExchange())
                .with(START_TEST_ROUTING_KEY);
    }
}
